package com.yanqu.road.server.cmd.activity.pasture;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.PastureProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.pasture.PastureModule;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_PASTURE_GAME_PASS, desc = "通关")
public class PastureGamePassCmd extends AbstractCommand {

    private boolean isPractice;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        PastureProto.PastureGamePassReqMsg reqMsg = PastureProto.PastureGamePassReqMsg.parseFrom(packet.getBytes());
        isPractice = reqMsg.getIsPractice();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(PastureModule.class).gamePass(isPractice);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            PastureProto.PastureGamePassRespMsg.Builder respMsg = PastureProto.PastureGamePassRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_PASTURE_GAME_PASS, respMsg);
        }
    }
}
